//
//  JJInitMobileClientKernel.m
//  iosDemo
//
//  Created by hamilyjing on 2020/5/16.
//  Copyright © 2020 JJ. All rights reserved.
//

#import "JJInitMobileClientKernel.h"

#import "JJLog.h"
#import "JJServiceFactory.h"
#import "JJURLManager.h"
#import "NSData+JJ.h"
#import "JJTHttpTransportUrlConfigManager.h"

@implementation JJInitMobileClientKernel

+ (void)initKernel {
    [self initLog];
    [self initServiceFactory];
    [self initUrlConfig];
}

+ (void)initLog {
    // open below if you want to print log in product environment
//    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:@"JJLog_isOpen"];
//    [[NSUserDefaults standardUserDefaults] synchronize];
    
    NSNumber *swithState = [[NSUserDefaults standardUserDefaults] objectForKey:@"JJLog_isOpen"];
    if (swithState && swithState.boolValue)
    {
        [[JJLog sharedLog] startLogging];
        [JJLog sharedLog].haveLogCapability = YES;
    }
}

+ (void)initServiceFactory
{
    // you can use JJ_LOGIN_SUCCESS or JJ_LOGOUT for login status, otherwise change it anyone you want.
    [JJServiceFactory sharedServiceFactory].loginSuccessNotificationNameArray = @[@"JJ_LOGIN_SUCCESS"];
    [JJServiceFactory sharedServiceFactory].logoutNotificationNameArray = @[@"JJ_LOGOUT"];
}

+ (void)initUrlConfig {
    
    // can change environment
    //    if ([JJCommonTools jj_canChangeEnvirement])
    //    {
    //        NSString *debugEnv = [JJCommonTools jj_getDebugEnvironment];
    //        if (0 == [debugEnv length])
    //        {
    //            [JJTHttpTransportUrlConfigManager sharedInstance].environmentName = [JJResourceManager sharedInstance].appConfig[@"EnvironmentName"];
    //        }
    //        else
    //        {
    //            [JJTHttpTransportUrlConfigManager sharedInstance].environmentName = debugEnv;
    //        }
    //    }
    //    else
    //    {
    //        [JJTHttpTransportUrlConfigManager sharedInstance].environmentName = [JJResourceManager sharedInstance].appConfig[@"EnvironmentName"];
    //    }
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"JJUrlConfig" ofType:@"json"];
    NSDictionary *urlConfigDic = [NSData jj_dictionaryWithJSONByFilePath:filePath];
    [[JJTHttpTransportUrlConfigManager sharedInstance] addUrlConfig:urlConfigDic];
}

@end
